package com.mcxx.modules.extremepoverty.service.impl;

import com.mcxx.modules.extremepoverty.service.ExRescueQueryExportService;
import com.mcxx.modules.base.utils.QueryParamUtil;
import com.mcxx.modules.filemanage.easypoi.util.ExportExcelService;
import com.mcxx.modules.filemanage.file.service.FileService;
import com.mcxx.modules.miniSalvation.family.dto.ExMemberExcelDto;
import com.mcxx.modules.miniSalvation.family.dto.ExMemberExcelNewDto;
import com.mcxx.modules.miniSalvation.family.dto.MiniFamilyChangeExcelDTO;
import com.mcxx.modules.miniSalvation.family.dto.MiniMemberExcelDto;
import com.mcxx.modules.miniSalvation.family.param.SalvationFamilyChangeParam;
import com.mcxx.modules.miniSalvation.family.param.SalvationFamilyParam;
import com.mcxx.modules.miniSalvation.family.param.SalvationObjectParam;
import com.mcxx.modules.miniSalvation.order.service.read.OrderReadService;
import com.mcxx.modules.miniSalvation.salary.service.read.FamilySalaryChangeReadService;
import com.mcxx.modules.miniSalvation.salary.service.read.MemberSalaryChangeReadService;
import com.mcxx.modules.system.entity.TaskExportEntity;
import com.mcxx.modules.system.service.write.TaskExportWriteService;
import com.mcxx.util.CommonUtil;
import com.mcxx.util.Constant;
import com.mcxx.util.DateUtil;
import com.yinhai.ta404.component.audit.vo.ExcelInfo;
import com.yinhai.ta404.core.security.vo.UserAccountVo;
import com.yinhai.ta404.core.service.BaseService;
import com.yinhai.ta404.core.transaction.annotation.TaTransactional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
@TaTransactional
public class ExRescueQueryExportServiceImpl extends BaseService implements ExRescueQueryExportService {

    @Resource
    private ExportExcelService exportExcelService;
    @Autowired
    private OrderReadService orderReadService;
    @Autowired
    private FamilySalaryChangeReadService familySalaryChangeReadService;
    @Autowired
    private FileService fileService;
    @Autowired
    private TaskExportWriteService taskExportWriteService;
    @Autowired
    private MemberSalaryChangeReadService memberSalaryChangeReadService;


    public ExcelInfo exportExcel(String exportType, List<String> orderIdList, SalvationObjectParam param, UserAccountVo accountVo){
        ExcelInfo excelInfo = null;
        QueryParamUtil.setBaseParamValue(param,accountVo);
        param.setBusinessType(Constant.BusinessCode.TEKUN);
        if (CommonUtil.invalidArgs(param.getSendMonth())) {
            param.setSendMonth(DateUtil.getMonthString());
        }
        if("1".equals(exportType)){




            List<ExMemberExcelDto> list = orderReadService.exportExRescueMemberList(param);
            excelInfo = exportExcelService.exportOrgOpLogs(ExMemberExcelDto.class,list,"特困供养对象信息.xls",
                    "特困人员供养对象列表","特困人员供养对象列表",false,"familyRelation","masterName",
                    "masterIdcard","sendMonth","startMonth","age","nation","sex","healthState","workPower","workState","education",
                    "disabilityType","disabilityLevel","isAtSchool","masterName","masterIdcard","familyRelation","fristStarDate");
        }else if("2".equals(exportType)){

            param.setOrderIdsList(orderIdList);
            List<ExMemberExcelDto> list = orderReadService.exportExRescueFamilyList(param);
            excelInfo = exportExcelService.exportOrgOpLogs(ExMemberExcelDto.class,list,"特困供养家庭信息.xls",
                    "特困人员供养家庭列表","特困人员供养家庭列表",false,"salaryMember",
                    "reissuedSalaryNumber","familyRevenue","startMonth","sendMonth","remark");
        }

        return excelInfo;
    }


    @Override
    public ExcelInfo exportExcelFamilySave(SalvationFamilyParam param, UserAccountVo accountVo){
        ExcelInfo excelInfo = null;
        QueryParamUtil.setBaseParamValue(param,accountVo);
        param.setBusinessType(Constant.BusinessCode.TEKUN);
        if (CommonUtil.invalidArgs(param.getSendMonth())) {
            param.setSendMonth(DateUtil.getMonthString());
        }

        List<ExMemberExcelNewDto> list = orderReadService.exportExRescueList(param);
        excelInfo = exportExcelService.exportOrgOpLogs(ExMemberExcelNewDto.class,list,"特困供养家庭信息.xls",
                    "特困人员供养家庭列表","特困人员供养家庭列表",false);


        return excelInfo;
    }



    public ExcelInfo exportExcelChange(String exportType, List<String> orderIdList, SalvationFamilyChangeParam param, UserAccountVo accountVo){
        ExcelInfo excelInfo = null;
        QueryParamUtil.setBaseParamValue(param,accountVo);
        param.setBusinessType(Constant.BusinessCode.TEKUN);
        if("1".equals(exportType)){



            param.setMemberIdList(orderIdList);
            List<MiniMemberExcelDto> list = memberSalaryChangeReadService.exportMiniMemberChangeList(param);
            excelInfo = exportExcelService.exportOrgOpLogs(MiniMemberExcelDto.class,list,"特困对象动态信息.xls",
                    "特困保障对象动态列表","特困保障对象动态列表",false,"salaryMoney","changeBefore","changeAfter","startDate","isHelpPoor",
                    "docHelpPoor","helpPoorFlag","ruralObjectType","age","healthState","fristStarDate","checkDate");
        }else if("2".equals(exportType)){

            param.setOrderIdsList(orderIdList);
            List<MiniFamilyChangeExcelDTO> list = familySalaryChangeReadService.exportMiniFamilyChangeList(param);
            excelInfo = exportExcelService.exportOrgOpLogs(MiniFamilyChangeExcelDTO.class,list,"特困家庭动态信息.xls",
                    "特困保障家庭动态列表","特困保障家庭动态列表",false,"familyNumber","savePeopleNum","poorType","reason","supplyOrgName",
                    "supplyType","checkDate","startDate");
        }

        return excelInfo;
    }
}
